class CostCalculator:
    """成本计算器"""

    def __init__(self, parent=None):
        self.parent = parent
        self.total_cost = 0.0

    def calculate_cost(self, site_length, site_width, brick_length, brick_width, brick_height,
                       brick_price, sand_price, labor_price, stone_price, cement_price, mortar_price):
        """计算总成本"""
        try:
            site_area = site_length * site_width
            brick_count = site_area / (brick_length * brick_width)

            # 计算材料用量
            cement_usage = site_area * 0.2
            sand_usage = site_area * 0.5
            stone_usage = site_area * 0.3

            # 计算成本
            brick_cost = brick_count * brick_price
            sand_cost = sand_usage * sand_price
            labor_cost = site_area * labor_price
            stone_cost = stone_usage * stone_price
            cement_cost = cement_usage * cement_price
            mortar_cost = site_area * mortar_price

            self.total_cost = brick_cost + sand_cost + labor_cost + stone_cost + cement_cost + mortar_cost

        except Exception as e:
            print(f"成本计算错误: {str(e)}")
            self.total_cost = 0.0